from flask import Flask,jsonify,request,Blueprint
from common.res import (getRes,getErrorRes,getSuccessRes)
from common.sqlInjectionSecurity import sqlEscape,sqlEscapeField

from DAL.paymentInfoDAL import paymentInfoDAL

paymentInfo = Blueprint('paymentInfo',__name__)

@paymentInfo.route("/paymentInfo/getList",methods=['POST','GET'])
def getList():
    dal = paymentInfoDAL()
    data = dal.getList()
    res = getSuccessRes(data=data)
    return jsonify(res)
@paymentInfo.route("/paymentInfo/getListById",methods=['POST','GET'])
def getListById():
    id = request.form.get('id') or None
    if not id:
        res = getErrorRes("参数id必须填写！")
        return jsonify(res)
    dal = paymentInfoDAL()
    data = dal.getListById(id)
    res = getSuccessRes(data=data)
    return jsonify(res)
@paymentInfo.route("/paymentInfo/update",methods=['POST'])
def update():
    param = {
        'id': request.form.get('id') or None,
        'salesman': request.form.get('salesman') and sqlEscape(request.form.get('salesman')) or None,
        'account': request.form.get('account') and sqlEscape(request.form.get('account')) or None,
        'money': request.form.get('money') or None,
        'order_form': request.form.get('order_form') or None,
        'order_status': request.form.get('order_status') or None,
        'payment_time': request.form.get('payment_time') or None,
        'recharge_status': request.form.get('recharge_status') or None,
        'game': request.form.get('game') and sqlEscape(request.form.get('game')) or None,
        'return_message': request.form.get('return_message') and sqlEscape(request.form.get('return_message')) or None
    }
    if not param['id']:
        res = getErrorRes("参数id必须填写！")
        return jsonify(res)

    dal = paymentInfoDAL()
    data = dal.update(**param)
    res = getSuccessRes(data=data)
    return jsonify(res)
@paymentInfo.route("/paymentInfo/removeById",methods=['POST'])
def removeById():
    id = request.form.get('id') or None
    if not id:
        res = getErrorRes("参数id必须填写！")
        return jsonify(res)
    dal = paymentInfoDAL()
    data = dal.removeById(id)
    res = getSuccessRes(data=data)
    return jsonify(res)
@paymentInfo.route("/paymentInfo/add",methods=['POST'])
def add():
    param = {
        'salesman': request.form.get('salesman') and sqlEscape(request.form.get('salesman')) or None,
        'account': request.form.get('account') and sqlEscape(request.form.get('account')) or None,
        'money': request.form.get('money') or None,
        'order_form': request.form.get('order_form') or None,
        'order_status': request.form.get('order_status') or None,
        'payment_time': request.form.get('payment_time') or None,
        'recharge_status': request.form.get('recharge_status') or None,
        'game': request.form.get('game') and sqlEscape(request.form.get('game')) or None,
        'return_message': request.form.get('return_message') and sqlEscape(request.form.get('return_message')) or None
    }
    dal = paymentInfoDAL()
    data = dal.add(**param)
    res = getSuccessRes(data=data)
    return jsonify(res)
